﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="PropertyChangingAttribute.cs" company="JDML Consulting Ltd.">
//   Copyright 2011 Photon Project - http://photon.codeplex.com
// </copyright>
// <summary>
//   Defines the PropertyChangingAttribute type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Photon.ComponentModel.Modelling
{
    using System;

    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Class)]
    public abstract class PropertyChangingAttribute : Attribute
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="PropertyChangingAttribute"/> class.
        /// </summary>
        protected PropertyChangingAttribute()
        {
            Priority = Int32.MaxValue;
        }

        /// <summary>
        /// Called before a property value is set.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <param name="property">The property.</param>
        /// <param name="oldValue">The old property value.</param>
        /// <param name="newValue">The new property value.</param>
        /// <returns><c>true</c> if the new value can be applied; otherwise <c>false</c>.</returns>
        public abstract bool OnChanging(object instance, MetaModelProperty property, object oldValue, ref object newValue);
        
        /// <summary>
        /// Gets or sets the priority of the attribute.
        /// </summary>
        /// <value>The priority of the attribute.</value>
        public int Priority
        {
            get; set;
        }
    }
}
